import java.awt.Color;


@SuppressWarnings("serial")
public class NendoColor extends java.awt.Color{
	int red;
	int green;
	int blue;
	public final int GRAYSCALE_LEVEL = 127; 
	
	public NendoColor(int r, int g, int b) {
		super(r, g, b);
		this.red = r;
		this.green = g;
		this.blue = b;
	}
	
	public NendoColor(Color c){
		this(c.getRed(),c.getGreen(),c.getBlue());
	}
	
	
	public Color alterColor(String re){
		int deep = 60;
		int r = this.red;
		int g = this.green;
		int b = this.blue;
		if(re.contentEquals("r")){
			if(r > deep) r -= deep;
			else r = -(r-deep);
			if(g > deep) g -= deep; 
			else g = -(g-deep);
			if(b > deep) b -= deep; 
			else b = -(b-deep);
		}
		else{
			if(r >= GRAYSCALE_LEVEL) r = -(r-deep); 
			else r += deep;
			if(g >= GRAYSCALE_LEVEL) g = -(g-deep); 
			else g += deep;
			if(b >= GRAYSCALE_LEVEL) b = -(b-deep); 
			else b += deep;
		}
		this.red = r;
		this.green = g;
		this.blue = b;
		return new Color(Math.abs(this.red),Math.abs(this.green),Math.abs(this.blue));
	}
	
	/* Simple method as macro */
	public Color alter(){
		return alterColor("");
	}
	
	public Color revert(){
		return alterColor("r");
	}
	
	/* end */
	
	public Color getColor(){
		return new Color(this.red,this.green,this.blue);
	}
	public static int abs(int n){
		if(n < 0) return -n;
		return n;
	}
	
	private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
	
	public static String hexToColor(Color a){
		String hex = "#"+(getCharPosition(a.getRed()/16))+(getCharPosition(a.getRed()%16))
						+(getCharPosition(a.getGreen()/16))+(getCharPosition(a.getGreen()%16))
						+(getCharPosition(a.getBlue()/16))+(getCharPosition(a.getBlue()%16));
		return hex;
	}
	
	public static char getCharPosition(int i){
		return HEX_CHARS[i];
	}
	
	
}
